﻿using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using CodeStash.Common.DataAccess.EntityFramework;

namespace CodeStash.Models.Snippet
{
    public class OpenFromWebViewModel
    {
        #region Ctor
        /// <summary>
        /// For Post request where ModelBinding takes care of matching up properties for us
        /// </summary>
        public OpenFromWebViewModel()
        {
            LanguageList = new List<Language>();

        }
        #endregion

        #region Public Properties

        public List<Language> LanguageList { get; set; }

        [Required(ErrorMessage = "You must enter a value for Language")]
        public int LanguageId { get; set; }


        [Required(ErrorMessage = "You must enter a value for FileName")]
        public string FileName { get; set; }

        public string ActualCode { get; set; }

        public string HighlightingCSS { get; set; }

        public string LanguageCode
        {
            get
            {
                return LanguageList != null ?
                    LanguageList.Where(x => x.LanguageId == LanguageId).Single().LanguageCode : "";
            }
        }



        public bool CodeHasBeenParsed { get; set; }

        #endregion
    }

}